package com.weishi.project.training.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import java.util.Arrays;
import com.weishi.project.training.domain.DynamometerRanking;
import com.weishi.project.training.service.IDynamometerRankingService;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.web.page.TableDataInfo;

/**
 * 测功仪成绩排名Controller
 */
@RestController
@RequestMapping("/training/dynamometerRanking")
public class DynamometerRankingController extends BaseController {

    @Autowired
    private IDynamometerRankingService dynamometerRankingService;

    /**
     * 查询测功仪成绩排名列表
     */
    @PreAuthorize("@ss.hasPermi('training:ranking:list')")
    @GetMapping("/list")
    public TableDataInfo list(DynamometerRanking dynamometerRanking) {
        startPage();
        List<DynamometerRanking> list = dynamometerRankingService.selectDynamometerRankingList(dynamometerRanking);
        return getDataTable(list);
    }

    /**
     * 导出测功仪成绩排名列表
     */
    @PreAuthorize("@ss.hasPermi('training:ranking:export')")
    @Log(title = "测功仪成绩排名", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DynamometerRanking dynamometerRanking) {
        List<DynamometerRanking> list = dynamometerRankingService.selectDynamometerRankingList(dynamometerRanking);
        ExcelUtil<DynamometerRanking> util = new ExcelUtil<DynamometerRanking>(DynamometerRanking.class);
        return util.exportExcel(list, "ranking");
    }

    /**
     * 获取测功仪成绩排名详细信息
     */
    @PreAuthorize("@ss.hasPermi('training:ranking:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(dynamometerRankingService.getById(id));
    }

    /**
     * 新增测功仪成绩排名
     */
    @PreAuthorize("@ss.hasPermi('training:ranking:add')")
    @Log(title = "测功仪成绩排名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DynamometerRanking dynamometerRanking) {
        dynamometerRankingService.save(dynamometerRanking);
        return AjaxResult.success();
    }

    /**
     * 修改测功仪成绩排名
     */
    @PreAuthorize("@ss.hasPermi('training:ranking:edit')")
    @Log(title = "测功仪成绩排名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DynamometerRanking dynamometerRanking) {
        dynamometerRankingService.updateById(dynamometerRanking);
        return AjaxResult.success();
    }

    /**
     * 删除测功仪成绩排名
     */
    @PreAuthorize("@ss.hasPermi('training:ranking:remove')")
    @Log(title = "测功仪成绩排名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        dynamometerRankingService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }
    
}